package plugin;

import static org.junit.Assert.*;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class ConfigProcessorTest {
	private static String testFileName = "test.xml";

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		FileWriter testWriter = new FileWriter(testFileName);
		PrintWriter out = new PrintWriter(new BufferedWriter(testWriter));
		out.println("<?xml version=\"1.0\"?>");
		out.println("<plugins>");
		out.println("<plugin class=\"test1\"></plugin>");
		out.println("<plugin class=\"test2\"></plugin>");
		out.println("<plugin class=\"test3\"></plugin>");
		out.println("</plugins>");
		out.flush();
		out.close();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		File file = new File(testFileName);
		file.delete();
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() throws IOException {
		ConfigProcessor cp = new ConfigProcessor();
		List<PluginDescriptor> plugins = cp.parseConfig(testFileName);
		assertEquals(plugins.size(), 3);
		assertEquals(plugins.get(0).getClassName(), "test1");
		assertEquals(plugins.get(1).getClassName(), "test2");
		assertEquals(plugins.get(2).getClassName(), "test3");
	}

}
